<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match="/">
		<kml xmlns="http://www.opengis.net/kml/2.2"> <xsl:text>&#xa;</xsl:text>
		<Document><xsl:text>&#xa;</xsl:text>
		<Style id="taskStyle">
      	<IconStyle>
	        <Icon>
	          <href>http://maps.google.com/mapfiles/kml/shapes/caution.png</href>
	        </Icon>
      	</IconStyle>
    	</Style><xsl:text>&#xa;</xsl:text>
    	<Style id="teamStyle">
      	<IconStyle>
	        <Icon>
	          <href>http://maps.google.com/mapfiles/kml/shapes/man.png</href>
	        </Icon>
      	</IconStyle>
    	</Style><xsl:text>&#xa;</xsl:text>
		<xsl:for-each select="//match">
			<xsl:variable name="taskID" select="taskid"/>
			<xsl:variable name="teamID" select="teamid"/>
			
			<Placemark>
				<LineString>
					<coordinates><xsl:text>&#xa;</xsl:text>
					<xsl:value-of select="//post[type='task'][id=concat($taskID, '')]/geotag/lon"></xsl:value-of>,<xsl:value-of select="//post[type='task'][id=concat($taskID, '')]/geotag/lat"></xsl:value-of>,0<xsl:text>&#xa;</xsl:text>
					<xsl:value-of select="//post[type='resource'][id=concat($teamID, '')]/geotag/lon"></xsl:value-of>,<xsl:value-of select="//post[type='resource'][id=concat($teamID, '')]/geotag/lat"></xsl:value-of>,0<xsl:text>&#xa;</xsl:text>
					</coordinates>
			   </LineString>
			</Placemark><xsl:text>&#xa;</xsl:text>
			
			<Placemark>
				<name>
					<xsl:value-of select="//post[type='task'][id=concat($taskID, '')]/name"></xsl:value-of>
				</name>
				<description>
					<xsl:value-of select="//post[type='task'][id=concat($taskID, '')]/content"></xsl:value-of>
				</description>
				<styleUrl>#taskStyle</styleUrl>
				<Point>
					<coordinates><xsl:value-of select="//post[type='task'][id=concat($taskID, '')]/geotag/lon"></xsl:value-of>,<xsl:value-of select="//post[type='task'][id=concat($taskID, '')]/geotag/lat"></xsl:value-of></coordinates>
				</Point>
			</Placemark><xsl:text>&#xa;</xsl:text>
			
			<Placemark>
				<name>
					<xsl:value-of select="//post[type='resource'][id=concat($teamID, '')]/name"></xsl:value-of>
				</name>
				<description>
					<xsl:value-of select="//post[type='resource'][id=concat($teamID, '')]/content"></xsl:value-of>
				</description>
				<styleUrl>#teamStyle</styleUrl>
				<Point>
					<coordinates><xsl:value-of select="//post[type='resource'][id=concat($teamID, '')]/geotag/lon"></xsl:value-of>,<xsl:value-of select="//post[type='resource'][id=concat($teamID, '')]/geotag/lat"></xsl:value-of></coordinates>
				</Point>
			</Placemark><xsl:text>&#xa;</xsl:text>
			
		</xsl:for-each>
		<xsl:text>&#xa;</xsl:text></Document>
		</kml>
	</xsl:template>
</xsl:stylesheet>